<template>
  <div class="admin-layout">
    <Sidebar />
    <div class="content-wrapper">
      <header class="main-header">

        <div class="user-profile">
          <div class="user-avatar">管</div>
          <span>{{ nickname }}</span>
        </div>
      </header>
      <main class="main-content">
        <router-view v-slot="{ Component }" :key="$route.fullPath">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </main>
    </div>
  </div>
</template>

<script setup>
import { computed,ref , onMounted} from 'vue';
import { useRoute,useRouter } from 'vue-router';
import Sidebar from '../components/Sidebar.vue';
import axios from "@/utils/axios";
let nickname = ref(null);

const router = useRouter();

onMounted(() => {

  axios.post("/api/admins/selById?adminId="+ localStorage.getItem("adminId"))
      .then(res => {
        console.log("layout",res)
        nickname.value = res.data.username
      })
})
const currentRouteName = computed(() => {
  return route.meta.title || route.name || 'Dashboard';
});
</script>

<style scoped>
.admin-layout {
  display: flex;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.content-wrapper {
  flex: 1;
  margin-left: 250px;
  display: flex;
  flex-direction: column;
}

.main-header {
  background: white;
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e9ecef;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  flex-shrink: 0;
}

.main-header h1 {
  font-size: 22px;
  font-weight: 600;
  color: #2c3e50;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

/* 头像背景色使用沉稳的深灰色 */
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #546e7a;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
}

.main-content {
  flex-grow: 1;
  padding: 30px;
  overflow-y: auto;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>